//Ajax.Responders.register({
//    onCreate: function() {
//        Element.show('ajax_indicator_hider');
//        Element.show('ajax_indicator');
//    },
//    onComplete: function() {
//        Element.hide('ajax_indicator_hider');
//        Element.hide('ajax_indicator');
//    }
//});

function preventSelection(element){
    var preventSelection = false;

    function addHandler(element, event, handler){
        if (element.attachEvent)
            element.attachEvent('on' + event, handler);
        else
        if (element.addEventListener)
            element.addEventListener(event, handler, false);
    }
    function removeSelection(){
        if (window.getSelection) {
            window.getSelection().removeAllRanges();
        }
        else if (document.selection && document.selection.clear)
            document.selection.clear();
    }
    function killCtrlA(event){
        var event = event || window.event;
        var sender = event.target || event.srcElement;

        if (sender.tagName.match(/INPUT|TEXTAREA/i))
            return;

        var key = event.keyCode || event.which;
        if (event.ctrlKey && key == 'A'.charCodeAt(0))  // 'A'.charCodeAt(0) можно заменить на 65
        {
            removeSelection();

            if (event.preventDefault)
                event.preventDefault();
            else
                event.returnValue = false;
        }
    }

    addHandler(element, 'mousemove', function(){
        if(preventSelection)
            removeSelection();
    });
    addHandler(element, 'mousedown', function(event){
        var event = event || window.event;
        var sender = event.target || event.srcElement;
        preventSelection = !sender.tagName.match(/INPUT|TEXTAREA/i);
    });

    addHandler(element, 'mouseup', function(){
        if (preventSelection)
            removeSelection();
        preventSelection = false;
    });

    addHandler(element, 'keydown', killCtrlA);
    addHandler(element, 'keyup', killCtrlA);
}

function removeEditor() {
    tinyMCE.execCommand('mceRemoveControl', false, 'textblock_content');
}

Array.prototype.max = function(){
	return Math.max.apply({},this)
}

Event.observe(window, "load", function() {
    $$('a > img').each(function(s) {
        s.up().addClassName('img')
    });

    if ($$('div.sider').length != "") {
        if ($$('div.sider')[0].empty()) {
            $$('div.sider')[0].setStyle({
                display: 'none'
            })
            $$('div.sider')[0].up().down('div.content').setStyle({
                marginRight: '0'
            })

        }
    }

    $$("div.actions").each(function(elem) {
        elem.absolutize();
    });


    $$("span.editable").each(function(elem){
        preventSelection(elem);
    });
    
    var lh = 0; if ($('services_list')) lh = $('services_list').getHeight();
    var rh = 0; if ($('services_list_right')) rh = $('services_list_right').getHeight();
    var mh = 0; if ($('service_description')) mh = $('service_description').getHeight();
    
    var h = [lh, rh, mh].max();
    if ($('services_list')) $('services_list').setStyle({height: h + 'px'});
    if ($('services_list_right')) $('services_list_right').setStyle({height: h + 'px'});
});
